package com.fei.yygh.hosp.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.fei.yygh.hosp.repository.ScheduleRepository;
import com.fei.yygh.hosp.service.DepartmentService;
import com.fei.yygh.hosp.service.ScheduleService;
import com.fei.yygh.model.hosp.Department;
import com.fei.yygh.model.hosp.Schedule;
import com.fei.yygh.vo.hosp.ScheduleQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

@Service
public class ScheduleServiceImpl implements ScheduleService {
    @Autowired
    private ScheduleRepository scheduleRepository;


    //上传排班接口信息
    @Override
    public void save(Map<String, Object> objectMap) {

        String objectMapStr = JSONObject.toJSONString(objectMap);
        //将Map集合转换为对象
        Schedule schedule = JSONObject.parseObject(objectMapStr, Schedule.class);

        //查询
        Schedule scheduleExist = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(schedule.getHoscode(),schedule.getHosScheduleId());
        //判断是否存在
        if(scheduleExist != null) {
            scheduleExist.setUpdateTime(new Date());
            scheduleExist.setIsDeleted(0);
            scheduleExist.setStatus(1);
            scheduleRepository.save(scheduleExist);
        }else {
            schedule.setIsDeleted(0);
            schedule.setUpdateTime(new Date());
            schedule.setCreateTime(new Date());
            scheduleExist.setStatus(1);
            scheduleRepository.save(schedule);
        }
    }

    //分页查询
    @Override
    public Page<Schedule> findPageSchedule(int page, int limit, ScheduleQueryVo scheduleQueryVo) {
        return null;
    }
}
